package com.dsj.app.service.impl;

import com.dsj.app.service.SupplierService;
import com.dsj.app.mapper.SupplierMapper;
import com.dsj.app.domain.Supplier;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;


@Service
public class SupplierServiceImpl implements SupplierService {

  @Autowired
  SupplierMapper supplierMapper;

  @Override
  public Supplier selectByPrimaryKey(String id) {
    return supplierMapper.selectByPrimaryKey(id);
  }

  @Override
  public List<Supplier> selectAllSupplier(Map<String, Object> params) {
    return supplierMapper.selectAllSupplier(params);
  }

  @Override
  public int count() {
    return supplierMapper.count();
  }

  @Override
  public int insertSupplier(Supplier supplier) {
    Supplier virtual = supplierMapper.selectByPrimaryKey(supplier.getId());
    if (null != virtual) {
      throw new IllegalArgumentException("该编号已经存在");
    }
    return supplierMapper.insertSelective(supplier);
  }

  @Override
  public int deleteSupplier(String id) {
    return supplierMapper.deleteByPrimaryKey(id);
  }

  @Override
  public int updateSupplier(Supplier supplier) {
    return supplierMapper.updateByPrimaryKeySelective(supplier);
  }
}
